package com.dbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dbms.domain.entity.FloodmapStationPropagate;
import com.dbms.domain.vo.FloodmapStationPropagateVO;
import com.dbms.mapper.FloodmapStationPropagateMapper;
import com.dbms.service.FloodmapStationPropagateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class FloodmapStationPropagateServiceImpl implements FloodmapStationPropagateService {

    final FloodmapStationPropagateMapper mapper;

    @Override
    public List<FloodmapStationPropagateVO> getListBySiteId(Long siteId) {
        List<FloodmapStationPropagate> list = mapper.selectList(new LambdaQueryWrapper<FloodmapStationPropagate>()
                .eq(FloodmapStationPropagate::getRiverId,siteId)
        );
        List<FloodmapStationPropagateVO> result = new ArrayList<>(list.size());
        for (FloodmapStationPropagate entity : list) {
            FloodmapStationPropagateVO vo = new FloodmapStationPropagateVO();
            vo.setId(entity.getId());
            vo.setStationName(entity.getStationName());
            vo.setStationCode(entity.getStationCode());
            result.add(vo);
        }
        return result;
    }

    @Override
    public FloodmapStationPropagate getById(String id) {
        return mapper.selectById(id);
    }

    @Override
    public FloodmapStationPropagate getByStationCod(String stationCode) {
        return mapper.selectOne(new LambdaQueryWrapper<FloodmapStationPropagate>().eq(FloodmapStationPropagate::getStationCode,stationCode));
    }
}
